﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KTXD.Data;
using KTXD.Entities;
using System.Threading;

namespace UserKTXD
{
    public partial class Chi_Tiet_Album : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if (Request.Params["Id"] != null)
                {
                    Pager1.CurrentIndex = 1;
                    HienThiHinhAnh(Pager1.CurrentIndex);
                }
            }
        }

        private void HienThiHinhAnh(int PageNo)
        {
            int TotalRows = 0;
            string WhereClause = "1=1";
            WhereClause += " and IdBoSuuTap = " + Request.Params["Id"];
            BoSuuTap ent_BoSuuTap = DataRepository.BoSuuTapProvider.GetById(Convert.ToInt32(Request.Params["Id"]));
            lbtieude.Text = ent_BoSuuTap.Ten;
            litTieuDe.Text = ent_BoSuuTap.Ten;
            TList<HinhAnh> TList_HinhAnh = DataRepository.HinhAnhProvider.GetPaged(WhereClause, "Id DESC", PageNo - 1, Pager1.PageSize, out TotalRows);
            drpHienAnh.DataSource = TList_HinhAnh;
            drpHienAnh.DataBind();
            Pager1.ItemCount = TotalRows;
            if (TotalRows <= Pager1.PageSize)
                Pager1.Visible = false;
            else
                Pager1.Visible = true;
        }

        protected void Pager1_Command(object sender, CommandEventArgs e)
        {
            Thread.Sleep(1000);
            int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
            Pager1.CurrentIndex = currnetPageIndex;
            HienThiHinhAnh(Pager1.CurrentIndex);
        }
    }
}